class Lazy {
    constructor(name) {
        this.name = name
        this.tasks = []
        // setTimeout(() => {
        //     this.run()
        // }, 0);
    }

    // sleep
    sleep() {
        return this;
    }

    // run
    run() {
        const event = this.tasks.shift()
        event && event()
        return this;
    }

    sleep(time) {
        const fn = () => {
            console.log('正在睡眠...');
            setTimeout(() => {
                this.run()
            }, time);
        }
        this.tasks.push(fn)
        return this;
    }

    // eat
    eat(foodname) {
        const fn = () => {
            console.log('eatting' + foodname);
            this.run()
        }
        this.tasks.push(fn)
        return this;
    }

    play(ballName) {
        const fn = () => {
            console.log('play' + ballName);
            this.run()
        }

        this.tasks.push(fn)
        return this;
    }

    start() {
        this.run()
    }
}

const lazy = new Lazy('hah')
lazy.eat('water').play('basketBall').sleep(2000).eat('苹果').play("football").start()